package com.nanxhs.health.starter.service;

import com.nanxhs.health.starter.properties.HealthProperties;
import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * 监控核心类
 *
 * @author 唐海斌
 * @date 2021/8/13 15:06
 */
@Slf4j
public class MonitorCore {

    private final HealthProperties healthProperties;

    private static final ScheduledThreadPoolExecutor scheduledExecutorService = new ScheduledThreadPoolExecutor(1);

    public MonitorCore(HealthProperties healthProperties) {
        this.healthProperties = healthProperties;
        init();
    }

    private void init() {
        scheduledExecutorService.scheduleWithFixedDelay(this::sendPack, 1, healthProperties.getDelay(), TimeUnit.MINUTES);
    }

    /**
     * 发送心跳包
     */
    public void sendPack() {
        try {
            System.out.println("发送心跳包....");
        } catch (Exception e) {
            log.error("发送心跳包失败", e);
        }
    }
}
